import App from './App.vue';
import router from './router';
import store from './store';
import '@/assets/styles/rest.scss';
import 'element-plus/dist/index.css';
import 'nprogress/nprogress.css';
import createVersionPolling from '@/utils/checkVersion';
import { ElMessageBox } from 'element-plus';

import VxeUIAll from 'vxe-pc-ui';
import 'vxe-pc-ui/lib/style.css';
import VxeUITable from 'vxe-table';
import 'vxe-table/lib/style.css';

const app = createApp(App);

const modules = import.meta.glob('@/components/**/index.vue');
for (const path in modules) {
	const name = path.replace(/^.*\/components\//, '').split('/')[0];
	const component = defineAsyncComponent(modules[path]);
	app.component(name, component);
}
app.use(VxeUIAll);
app.use(VxeUITable);
app.use(router);
app.use(store);
app.mount('#app');
console.log(import.meta.env);

import.meta.env.MODE != 'dev' &&
	createVersionPolling({
		onUpdated: () => {
			ElMessageBox.confirm(
				'检测到页面有内容更新，为了功能的正常使用，是否立即刷新？',
				'提示',
				{
					confirmButtonText: '确认',
					showCancelButton: false,
					callback: () => {
						// self.onRefresh();
						window.location.reload();
					},
				}
			);
		},
	});
